<!--  -->
<template>
  <div class="wrapper">
    <van-list
      class="list"
      v-model="loading"
      :finished="finished"
      finished-text="全部加载完成"
      @load="onLoad"
    >
      <div
        v-for="item in list"
        :key="item.id"
        @click="$router.push({path:'/orderCar',query:{id:item.id}})"
      >
        <div class="box">
          <div class="header">
            <div class="car-name">
              <span>{{item.name}}</span>
              <span>{{item.model}}</span>
            </div>
            <div class="car-price">
              <span class="symbol">￥</span>
              <strong class="price">{{item.price}}</strong>
              <span class="day">/天</span>
            </div>
          </div>
          <div class="car-property">
            <span>{{item.property}}</span>
          </div>
          <div class="car-img">
            <img
              :src="item.image"
              alt=""
            />
          </div>
          <div class="footer">
            <span class="name">{{item.platform}}</span>
            <span class="good">优选</span>
            <span class="score">{{item.score}}</span>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { getHomeRecommend } from "../../../api/home";
export default {
  name: "Recommend",
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 0, // 0表示第一页，默认为第一页数据
    };
  },
  methods: {
    onLoad() {
      getHomeRecommend(this.page)
        .then((res) => {
          if (res.data.data.length === 0) {
            // 表示数据全部加载完毕
            this.finished = true;
          } else {
            this.list.push(...res.data.data);
            // 本页加载完毕
            this.loading = false;
            // 加载下一页
            this.page++;
          }
        })
        .catch((err) => {
          console.log(err);
          // 加载出错，关闭加载状态
          this.loading = false;
        });
    },
  },
};
</script>
<style lang='scss' scoped>
::v-deep.wrapper {
  .list {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    .van-list__loading {
      margin: 0 auto;
    }
    .van-list__finished-text {
      margin: 0 auto;
    }
    .box {
      width: 171px;
      height: 195px;
      background-color: white;
      border-radius: 10px;
      margin: 5px 0;
      display: flex;
      justify-content: center;
      flex-direction: column;
      .header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 10px 3px;
        .car-name {
          font-size: 15px;
        }
        .car-price {
          .symbol {
            color: #ff3434;
            font-size: 10px;
          }
          .price {
            color: #ff3434;
            font-size: 16px;
          }
          .day {
            font-size: 10px;
          }
        }
      }
      .car-property {
        span {
          font-size: 13px;
          letter-spacing: 1px;
          color: #999;
          padding: 0 10px;
        }
      }
      .car-img {
        display: flex;
        justify-content: center;
        align-items: center;
        border-bottom: 2px solid #e5e5e5;
        width: 153.86px;
        height: 100px;
        margin-left: 7px;
        img {
          width: 153.86px;
          height: 100px;
        }
      }
      .footer {
        display: flex;
        justify-content: start;
        align-items: center;
        height: 16px;
        line-height: 16px;
        padding: 0 10px;
        margin-top: 10px;
        span {
          font-size: 13px;
        }
        .name {
          margin-right: 4px;
        }
        .good {
          margin-right: 4px;
          display: inline-block;
          width: 29px;
          height: 16px;
          background: linear-gradient(270deg, #fbc19e, #fdddc6);
          line-height: 16px;
          text-align: center;
        }
        .score {
          color: #ff3434;
        }
      }
    }
  }
}
</style> 